Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canonicalize paths before stripping current dir as prefix #6290

Merged
merged 4 commits into from
Mar 30, 2023

Conversation

jazzfool
Copy link
Contributor

@jazzfool jazzfool commented Mar 13, 2023

Fixes #6182

the-mikedavis
the-mikedavis previously approved these changes Mar 13, 2023
@the-mikedavis the-mikedavis added C-bug Category: This is a bug A-core Area: Helix core improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Mar 13, 2023
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the right fix.

Yes this does fix the very specific instance you ran into but it doesn't adress the root cause of the problem. Right now you only canonicalize the paths if they exist. (also you crash the editor if CWD doesn't exist, we do that elsewhere too but we really shouldn't do that). If clangd had sent a message for a file that is not yet saved to disk (but exists as a buffer in helix) the same problem would occur. Furthermore there also many other places where we canonicalize paths in helix where having the normal canonicalization/normalization function being unreliable is a problem too and can lead to similar bugs.

As I described here: #6182 (comment) you need to change get_normalized_path to canonicalize the first parent that exists (and normalize the rest with the existing code). You can then use that function to normalize cwd (and the argument) in get_relative_path

@pascalkuthe pascalkuthe added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Mar 13, 2023
@jazzfool jazzfool force-pushed the fix-windows-paths branch from e0f2c4a to 02ebcff Compare March 14, 2023 08:32
@jazzfool jazzfool requested review from pascalkuthe and removed request for archseer March 15, 2023 03:07
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great now, thanks for sticking with it! one minor nit

Comment on lines 47 to 54
.find(|path| path.exists())
.and_then(|path| Some((path, dunce::canonicalize(path).ok()?)))
.map(|(base, canonicalized)| {
(
canonicalized,
path.strip_prefix(base).unwrap(/* base is an ancestor of path */).into(),
)
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.find(|path| path.exists())
.and_then(|path| Some((path, dunce::canonicalize(path).ok()?)))
.map(|(base, canonicalized)| {
(
canonicalized,
path.strip_prefix(base).unwrap(/* base is an ancestor of path */).into(),
)
})
.find_map(|base| {
let canonicalized_base = dunce::canonicalize(base).ok()?;
Some((canonicalized_base, path.strip_prefix(base)))
})

just because a path exists doesn't mean cannonicalization necessary successed (Sadly). Using find_map ensures we only stoip once canonicalization succedes. It's also a bit cleaner.

Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(didn't mean to approve yet until you accept my suggestion 😅 )

Test suite also needs to ne updated in a couple places (the previous paths assumed that we wouldn't cannonicalize)

@pascalkuthe pascalkuthe added S-waiting-on-review Status: Awaiting review from a maintainer. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 18, 2023
pascalkuthe
pascalkuthe previously approved these changes Mar 18, 2023
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah whoops I didn't see the conflict with #6156. Could you rebase this?

@the-mikedavis the-mikedavis added this to the next milestone Mar 20, 2023
@pascalkuthe pascalkuthe added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Mar 22, 2023
@the-mikedavis the-mikedavis merged commit d04288e into helix-editor:master Mar 30, 2023
Triton171 pushed a commit to Triton171/helix that referenced this pull request Jun 18, 2023
wes-adams pushed a commit to wes-adams/helix that referenced this pull request Jul 4, 2023
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Helix core improvements C-bug Category: This is a bug S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LSP (clangd) actions open duplicate buffers
3 participants